var e = getApp();

Page({
    data: {
        active: 0,
        page: 1,
        language: "",
        regional: "请选择快递公司",
        dateshow_1: !1,
        columns: [],
        checkList: [],
        orderPayId: "",
        options: [],
        dialogVisible: !1,
        expressName: "",
        numberName: "",
        addresseeInfo: {},
        showQrcode: !1,
        qrcode_url: "",
        sendGoogsFail: {
            show: !1,
            msg: ""
        },
        jurisdiction_set: 0
    },
    onLoad: function(e) {
        this.getData();
    },
    onClick: function(e) {
        var t = e.detail.index;
        this.setData({
            active: t,
            page: 1
        }), this.getData();
    },
    tapDetail: function(e) {
        console.log(e);
        var t = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: "/packageE/others/cloudwarehouse/cloudOrderDetail/cloudOrderDetail?id=" + t
        });
    },
    onReady: function() {},
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {
        if (!(this.data.current_page >= this.data.last_page)) {
            var e = this.data.page + 1;
            this.setData({
                page: e
            }), this.getMore();
        }
    },
    onShareAppMessage: function() {},
    getMore: function() {
        var t, a = this;
        0 == this.data.active ? t = "plugin.cloud-warehouse.frontend.order-list.index" : 1 == this.data.active ? t = "plugin.cloud-warehouse.frontend.order-list.waitSend" : 2 == this.data.active ? t = "plugin.cloud-warehouse.frontend.order-list.waitReceive" : 3 == this.data.active && (t = "plugin.cloud-warehouse.frontend.order-list.completed");
        var o = e.getNetAddresss(t);
        e._getNetWork({
            url: o,
            success: function(e) {
                var t = e.data;
                1 == t.result ? (console.log(t), a.setData({
                    info: a.data.info.concat(t.data.data),
                    current_page: t.data.current_page,
                    last_page: t.data.last_page
                })) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    getData: function() {
        var t, a = this;
        0 == this.data.active ? t = "plugin.cloud-warehouse.frontend.order-list.index" : 1 == this.data.active ? t = "plugin.cloud-warehouse.frontend.order-list.waitSend" : 2 == this.data.active ? t = "plugin.cloud-warehouse.frontend.order-list.waitReceive" : 3 == this.data.active && (t = "plugin.cloud-warehouse.frontend.order-list.completed");
        var o = e.getNetAddresss(t);
        e._getNetWork({
            url: o,
            data: {
                page: a.data.page
            },
            success: function(e) {
                var t = e.data;
                1 == t.result ? (console.log(t), a.setData({
                    info: t.data.data,
                    current_page: t.data.current_page,
                    last_page: t.data.last_page
                })) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1500
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    operation: function(e) {
        var t = e.currentTarget.dataset.item, a = e.currentTarget.dataset.order, o = e.currentTarget.dataset.orderidx;
        if (console.log(o), t.api || 41 == t.value) if (console.log(t), 8 == t.value) this._checklogistics(a, t); else if (12 == t.value) this._deleteOrder(a, t, o); else if (10 == t.value) this._comment(a, t); else if (1 == t.value) this._toPay(a, t); else if (13 == t.value) {
            this.getTemplate(a, t);
        } else 9 == t.value ? this._cancleOrder(a, t, o) : 5 == t.value ? this._confirmOrder(a, t) : 18 == t.value ? this._toRefundDetail(a, t) : "cashierPay" == t.value ? this._cashPayOrder(a, t) : "verification_code" == t.value ? this._verification(a, t) : 20 == t.value ? this._verificationCash(a, t) : 21 == t.value ? wx.navigateTo({
            url: "/packageD/member/myOrder/order_record/order_record?order_id=" + item.id
        }) : 22 == t.value ? (this.setData({
            orderPayId: a.id
        }), this._payMoney(a, t)) : "coupon" == t.value ? (console.log(a.id), wx.navigateTo({
            url: "/packageD/coupon_share/coupon_share?orderid=" + a.id
        })) : 23 == t.value || 60 == t.value ? (this.setData({
            orderPayId: a.id
        }), 3 == a.dispatch_type_id ? this.sendGoogs() : (this._getCompany(), this.setData({
            dialogVisible: !0
        })), this.triggerEvent("stoprefresh", !0), this.setData({
            expressName: "",
            numberName: ""
        })) : 24 == t.value || 61 == t.value ? (this.setData({
            orderPayId: a.id
        }), this._deliverGoodsCancel(a, t)) : 25 == t.value ? (this.setData({
            orderPayId: a.id
        }), this._collectGoods(a, t)) : 26 == t.value ? (this.setData({
            orderPayId: a.id
        }), this._closeOrderPay(a, t)) : 27 == t.value ? (this.setData({
            orderPayId: a.id
        }), this._evaluate(a, t)) : 28 == t.value ? this._truckList(t, a) : 41 == t.value || (50 == t.value ? this._checkInvoice(t, a) : 11 == t.value ? this.confirmHotelOrder(t.api, a.id) : "lease_toy_refund" == t.value || "package_deliver_clerk" == t.value ? (console.log("申请归还"), 
        this.getRuruen(t, a)) : "lease_toy_apply_adopt" == t.value ? (console.log("填写归还"), 
        wx.navigateTo({
            url: "/packageB/member/OrderReturn/OrderReturn?id=" + a.id
        })) : "lease_toy_return_info" == t.value ? (console.log("归还详情"), wx.navigateTo({
            url: "/packageA/others/order_ruturn_info/order_ruturn_info?id=" + a.id
        })) : "package_deliver" == t.value ? (console.log("自提点核销"), console.log(t.api), 
        this.getQrImg(t, a)) : "expediting_delivery" == t.value && (this.setData({
            orderPayId: a.id
        }), this.publicMessage(t, a, "提醒商家发货"))); else "expediting_delivery" == t.value ? wx.showToast({
            icon: "none",
            title: "已提醒过商家",
            duration: 1e3
        }) : wx.showToast({
            icon: "none",
            title: "error:错误4008820",
            duration: 1e3
        });
    },
    getQrImg: function(t, a) {
        var o = this, r = e.getNetAddresss(t.api);
        "package_deliver" == t.value ? r += "&order_id=" + a.id : r += "&order_pay_id=" + a.id, 
        e._getNetWork({
            url: r,
            success: function(e) {
                var t = e.data;
                1 == t.result ? o.setData({
                    showQrcode: !0,
                    qrcode_url: t.data.qr_code_url
                }) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    publicMessage: function(t, a, o) {
        var r = this;
        wx.showModal({
            title: "提示",
            content: "确定".concat(o, "?"),
            success: function(a) {
                if (a.confirm) {
                    var i = "";
                    i += e.getNetAddresss(t.api), i += "&order_id=" + r.data.orderPayId, e._getNetWork({
                        url: i,
                        success: function(e) {
                            1 == (e = e.data).result ? (r.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                icon: "success",
                                title: "".concat(o, "成功"),
                                duration: 1e3
                            })) : wx.showToast({
                                icon: "none",
                                title: e.msg,
                                duration: 1e3
                            });
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });
                }
            }
        });
    },
    onClose: function() {
        this.setData({
            showQrcode: !1
        });
    },
    _checklogistics: function(e, t) {
        console.log(e, t), wx.navigateTo({
            url: "/packageA/member/order/logistics/logistics?id=" + e.id + "&api=" + t.api
        });
    },
    getRuruen: function(t, a) {
        var o = this, r = e.getNetAddresss(t.api);
        r += "&order_id=" + a.id, e._getNetWork({
            url: r,
            success: function(e) {
                var t = e.data;
                1 == t.result ? (wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 1500
                }), o.triggerEvent("ConfrimOrderNotification")) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    _deleteOrder: function(e, t, a) {
        var o = this;
        wx.showModal({
            title: "提示",
            content: "确定删除此订单?",
            success: function(r) {
                if (r.confirm) {
                    var i = o.data.info;
                    i.splice(a, 1), o.setData({
                        info: i
                    }), o._sentRequest(t.api, "&order_id=" + e.id, !1);
                }
            }
        });
    },
    _sentRequest: function(t, a, o) {
        var r = e.getNetAddresss(t);
        r += a, e._getNetWork({
            url: r,
            success: function(e) {
                var t = e.data;
                1 == t.result ? wx.showToast({
                    title: t.msg,
                    icon: "none",
                    duration: 1500,
                    success: function() {
                        setTimeout(function() {
                            wx.navigateBack({
                                delta: 1
                            });
                        }, 1500);
                    }
                }) : wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    _comment: function(e, t) {
        wx.navigateTo({
            url: "/packageB/comment/comment?order=" + JSON.stringify(e || {})
        });
    },
    _toPay: function(e, t) {
        wx.navigateTo({
            url: "/packageD/buy/orderPay/orderPay?order_id=" + e.id + "&status=1"
        });
    },
    _toRefundDetail: function(e, t) {
        wx.navigateTo({
            url: "/packageD/member/myOrder/Aftersales/Aftersales?refund_id=" + e.refund_id
        });
    },
    _toRefund: function(e, t) {
        wx.navigateTo({
            url: "/packageD/member/myOrder/refund/refund?order_id=" + e.id + "&type=1"
        });
    },
    _cancleOrder: function(e, t, a) {
        var o = this;
        wx.showModal({
            title: "提示",
            content: "确定取消此订单?",
            success: function(r) {
                if (r.confirm) {
                    var i = o.data.info;
                    i.splice(a, 1), o.setData({
                        info: i
                    }), o._sentRequest(t.api, "&order_id=" + e.id, !1);
                }
            }
        });
    },
    _confirmOrder: function(t, a) {
        var o = this, r = e.getNetAddresss(a.api);
        r += "&order_id=" + t.id, wx.showModal({
            title: "提示",
            content: "您确定收到货物?",
            success: function(a) {
                a.confirm && e._getNetWork({
                    url: r,
                    success: function(e) {
                        var a = e.data;
                        1 == a.result ? o.triggerEvent("ConfrimOrderNotification", t.id) : wx.showToast({
                            icon: "none",
                            title: a.msg,
                            duration: 1e3
                        });
                    },
                    fail: function(e) {
                        console.log(e);
                    }
                });
            }
        });
    },
    _cashPayOrder: function(e, t) {
        var a = this;
        wx.showModal({
            title: "提示",
            content: "确定此订单已付款?",
            success: function(o) {
                o.confirm && a._sentRequest(t.api, "&order_id=" + e.id + "&order_pay_id=" + a.data.order_pay_id, !1);
            }
        });
    },
    _verification: function(e, t) {
        wx.navigateTo({
            url: "/packageD/member/myOrder/orderVerification/orderVerification?order_id=" + e.id + "&api=" + t.api
        });
    },
    _verificationCash: function(e, t) {
        var a = this;
        wx.showModal({
            title: "提示",
            content: "确定此订单已付款?",
            success: function(o) {
                o.confirm && a._sentRequest(t.api, "&order_id=" + e.id + "&order_pay_id=" + a.data.order_pay_id, !1);
            }
        });
    },
    _payMoney: function(t, a) {
        var o = this;
        wx.showModal({
            title: "提示",
            content: "确认支付该订单?",
            success: function(t) {
                if (t.confirm) {
                    var r = "";
                    "supplier" == o.data.orderType || "subsidiary" == o.data.orderType ? (r += e.getNetAddresss(a.api), 
                    r += "&order_id=" + o.data.orderPayId) : (r += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.pay"), 
                    r += "&order_id=" + o.data.orderPayId), e._getNetWork({
                        url: r,
                        success: function(e) {
                            var t = e.data;
                            1 == t.result ? (o.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                icon: "success",
                                title: "支付成功",
                                duration: 1e3
                            })) : wx.showToast({
                                icon: "none",
                                title: t.msg,
                                duration: 1e3
                            });
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });
                }
            }
        });
    },
    _getCompany: function() {
        var t = this, a = "";
        "supplier" == t.data.orderType ? a += e.getNetAddresss("plugin.supplier.frontend.order.express-company") : "subsidiary" == t.data.orderType ? a += e.getNetAddresss("plugin.subsidiary.frontend.order.express-company") : a += e.getNetAddresss("plugin.store-cashier.frontend.store.center.sendOrder"), 
        a += "&order_id=" + t.data.orderPayId, e._getNetWork({
            url: a,
            success: function(a) {
                var o = a.data;
                if (1 == o.result) {
                    t.setData({
                        options: o.data.express_companies
                    });
                    var r = t.data.options.map(function(e) {
                        return e.name;
                    });
                    e._isTextEmpty(o.data.jurisdiction_set) || t.setData({
                        jurisdiction_set: o.data.jurisdiction_set
                    }), t.setData({
                        columns: r,
                        addresseeInfo: o.data.address
                    });
                }
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    _deliverGoodsCancel: function(t, a) {
        var o = this;
        wx.showModal({
            title: "提示",
            content: "确定取消发货?",
            success: function(t) {
                if (t.confirm) {
                    var r = "";
                    "supplier" == o.data.orderType || "subsidiary" == o.data.orderType ? (r += e.getNetAddresss(a.api), 
                    r += "&order_id=" + o.data.orderPayId) : "auction" == o.data.orderType ? (r += e.getNetAddresss("plugin.auction.api.order-operation.cancel-send"), 
                    r += "&order_id=" + o.data.orderPayId) : (r += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.cancel-send"), 
                    r += "&order_id=" + o.data.orderPayId), e._getNetWork({
                        url: r,
                        success: function(e) {
                            var t = e.data;
                            1 == t.result ? (o.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                icon: "success",
                                title: "取消发货成功",
                                duration: 1e3
                            })) : wx.showToast({
                                icon: "none",
                                title: t.msg,
                                duration: 1e3
                            });
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });
                }
            }
        });
    },
    _collectGoods: function(t, a) {
        var o = this;
        wx.showModal({
            title: "提示",
            content: "确认收货?",
            success: function(t) {
                if (t.confirm) {
                    var r = "";
                    "supplier" == o.data.orderType || "subsidiary" == o.data.orderType ? (r += e.getNetAddresss(a.api), 
                    r += "&order_id=" + o.data.orderPayId) : (r += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.receive"), 
                    r += "&order_id=" + o.data.orderPayId), e._getNetWork({
                        url: r,
                        success: function(e) {
                            var t = e.data;
                            1 == t.result ? (o.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                icon: "success",
                                title: "收货成功",
                                duration: 1e3
                            })) : wx.showToast({
                                icon: "none",
                                title: t.msg,
                                duration: 1e3
                            });
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });
                }
            }
        });
    },
    _closeOrderPay: function(t, a) {
        var o = this;
        wx.showModal({
            title: "提示",
            content: "确定关闭订单?",
            success: function(t) {
                if (t.confirm) {
                    var r = "";
                    "supplier" == o.data.orderType || "subsidiary" == o.data.orderType ? (r += e.getNetAddresss(a.api), 
                    r += "&order_id=" + o.data.orderPayId) : (r += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.close"), 
                    r += "&order_id=" + o.data.orderPayId, r += "&shop_id=null"), e._getNetWork({
                        url: r,
                        success: function(e) {
                            1 == (e = e.data).result ? (o.triggerEvent("ConfrimOrderNotification", "pay"), wx.showToast({
                                icon: "success",
                                title: "关闭订单成功",
                                duration: 1e3
                            })) : wx.showToast({
                                icon: "none",
                                title: e.msg,
                                duration: 1e3
                            });
                        },
                        fail: function(e) {
                            console.log(e);
                        }
                    });
                }
            }
        });
    },
    _evaluate: function(e, t) {
        wx.navigateTo({
            url: "/packageD/member/myOrder/DeliveryEvaluate/DeliveryEvaluate?order_id=" + e.order_id + "&api=" + t.api + "&name=distributor"
        });
    },
    _truckList: function(e, t) {
        wx.navigateTo({
            url: "/packageD/member/myOrder/truckList/truckList?order_id=" + t.id
        });
    },
    _checkInvoice: function(e, t) {
        wx.navigateTo({
            url: "/packageD/member/myOrder/invoice/invoice?order_id=" + t.id
        });
    },
    numberNamebtn: function(e) {
        var t = e.detail.value;
        this.setData({
            numberName: t
        });
    },
    sendGoogs: function(t) {
        var a = this;
        if (t && "confirm" !== t.detail) this.setData({
            dialogVisible: !1
        }), this.triggerEvent("stoprefresh", !1); else {
            var o = this, r = function(e) {
                a.setData({
                    sendGoogsFail: {
                        show: !0,
                        msg: e
                    },
                    dialogVisible: !1
                });
            };
            if ("supplier" == this.data.orderType) {
                var i = "";
                i += e.getNetAddresss("plugin.supplier.frontend.order.send");
                var s = {
                    order_id: o.data.orderPayId,
                    express_code: o.data.expressName.value,
                    express_company_name: o.data.expressName.name,
                    express_sn: o.data.numberName
                };
                e._postNetWork({
                    url: i,
                    showToastIn: !1,
                    data: s,
                    success: function(e) {
                        var t = e.data;
                        console.log("msg=", t), 1 == t.result ? (o.setData({
                            dialogVisible: !1
                        }), o.triggerEvent("stoprefresh", !1), o.triggerEvent("ConfrimOrderNotification", "pay"), 
                        wx.showToast({
                            icon: "success",
                            title: "发货成功",
                            duration: 1e3
                        })) : r(t.msg);
                    },
                    fail: function(e) {}
                });
            } else if ("subsidiary" == this.data.orderType) {
                var n = "";
                n += e.getNetAddresss("plugin.subsidiary.frontend.order.send");
                var d = {
                    order_id: o.data.orderPayId,
                    express_code: o.data.expressName.value,
                    express_company_name: o.data.expressName.name,
                    express_sn: o.data.numberName
                };
                e._postNetWork({
                    url: n,
                    showToastIn: !1,
                    data: d,
                    success: function(e) {
                        var t = e.data;
                        1 == t.result ? (o.setData({
                            dialogVisible: !1
                        }), o.triggerEvent("stoprefresh", !1), o.triggerEvent("ConfrimOrderNotification", "pay"), 
                        wx.showToast({
                            icon: "success",
                            title: "发货成功",
                            duration: 1e3
                        })) : r(t.msg);
                    },
                    fail: function(e) {}
                });
            } else if ("auction" == this.data.orderType) {
                var c = "";
                c += e.getNetAddresss("plugin.auction.api.order-operation.send");
                var u = {
                    order_id: o.data.orderPayId,
                    express_code: o.data.expressName.value,
                    express_company_name: o.data.expressName.name,
                    express_sn: o.data.numberName
                };
                e._postNetWork({
                    url: c,
                    showToastIn: !1,
                    data: u,
                    success: function(e) {
                        var t = e.data;
                        1 == t.result ? (o.setData({
                            dialogVisible: !1
                        }), o.triggerEvent("stoprefresh", !1), o.triggerEvent("ConfrimOrderNotification", "pay"), 
                        wx.showToast({
                            icon: "success",
                            title: "发货成功",
                            duration: 1e3
                        })) : r(t.msg);
                    },
                    fail: function(e) {}
                });
            } else {
                var l = "";
                l += e.getNetAddresss("plugin.store-cashier.frontend.store.center.order-operation.send"), 
                l += "&order_id=" + o.data.orderPayId, l += "&express_code=" + o.data.expressName.value, 
                l += "&express_company_name=" + o.data.expressName.name, l += "&express_sn=" + o.data.numberName, 
                e._getNetWork({
                    url: l,
                    success: function(e) {
                        var t = e.data;
                        1 == t.result ? (console.log("result=", t.result), o.triggerEvent("ConfrimOrderNotification", "pay"), 
                        wx.showToast({
                            icon: "success",
                            title: "发货成功",
                            duration: 1e3
                        }), o.setData({
                            dialogVisible: !1
                        })) : r(t.msg);
                    },
                    fail: function(e) {}
                });
            }
        }
    },
    colseSendGoogsFailPopup: function() {
        this.setData({
            "sendGoogsFail.show": !1
        });
    },
    seleRegional: function() {
        this.setData({
            dateshow_1: !0
        });
    },
    onCancelbtn: function() {
        this.setData({
            dateshow_1: !1
        });
    },
    onConfirmbtn: function(e) {
        var t = e.detail.index, a = e.detail.value, o = this.data.options;
        this.setData({
            dateshow_1: !1,
            regional: a,
            expressName: o[t]
        });
    },
    noop: function() {},
    confirmHotelOrder: function(t, a) {
        var o = "";
        o += e.getNetAddresss(t), o += "&order_id=" + a, e._getNetWork({
            url: o,
            success: function(e) {
                var t = e.data;
                t.result, wx.showToast({
                    icon: "none",
                    title: t.msg,
                    duration: 1e3
                });
            },
            fail: function(e) {
                console.log(e);
            }
        });
    },
    copyorderbtn: function(e) {
        var t = e.currentTarget.dataset.copydata;
        wx.setClipboardData({
            data: t || "",
            success: function(e) {
                wx.showToast({
                    icon: "none",
                    title: "复制成功",
                    duration: 1e3
                });
            }
        });
    }
});